package cn.com.hutool;

import cn.com.task.TaskDemo;
import cn.com.task.TaskDemo2;
import cn.hutool.core.thread.ConcurrencyTester;
import cn.hutool.core.thread.ThreadUtil;
import org.junit.Test;
import java.util.concurrent.Future;

public class MainTest {

    /**
     * 测试无返回值多线程调用
     */
    @Test
    public void testExecute(){
        ThreadUtil.execute(new TaskDemo(2));
        System.out.println("主线程执行完毕！");
    }

    /**
     * 测试有返回值多线程调用
     */
    @Test
    public void testExecAsync() {
        Future<Integer> future = ThreadUtil.execAsync(new TaskDemo2(2));
        try {
            Integer result = future.get();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 多线程模拟并发访问的测试
     */
    @Test
    public void testConcurrencyTest(){
        ConcurrencyTester tester = ThreadUtil.concurrencyTest(100, new Runnable() {
            @Override
            public void run() {
                System.out.println("并发测试");
            }
        });
        long interval = tester.getInterval();
        System.out.println(interval);
    }
}
